const { I18n } = require('i18n')
const JsonMerge = require('js-json-merge')
const Check = require('./src/check.js')
const Rules = require('./src/rules/index.js')
const cn = require('./src/locales/cn.js')
const en = require('./src/locales/en.js')

class Validator{
	constructor(options){
		this.options = {
			local: 'cn',
			messages: {
				cn:cn,
				en:en
			},
			rules: Rules
		}
		this.options = JsonMerge(this.options,options)
		this.i18n = new I18n()
		this.i18n.configure({
			defaultLocale: this.options.local,
			staticCatalog: this.options.messages
		})
	}
	dumpOptions(){
		console.log(this.options)
	}
	setLang(lang){
		this.options.local = lang
		this.i18n.setLocale(lang)
	}
	check(values,rules,messages,attributes){
		return (new Check(this.options.rules,this.i18n)).run(values,rules,messages,attributes);
	}
}
module.exports = Validator